<script setup lang="ts">
import { computed } from 'vue'
import { useI18n } from 'vue-i18n'
import { useAppStore } from '../stores/counter'
import { ElSwitch, ElTooltip } from 'element-plus'

const { t } = useI18n()
const appStore = useAppStore()

const isChecked = computed({
  get: () => appStore.userMode === 'professional',
  set: (value: boolean) => {
    appStore.setUserMode(value ? 'professional' : 'simple')
  }
})

const tooltipText = computed(() => {
  return appStore.isProfessionalMode 
    ? t('mode.professional.tooltip')
    : t('mode.simple.tooltip')
})
</script>

<template>
  <div class="mode-switcher">
    <ElTooltip :content="tooltipText" placement="bottom">
      <div class="flex items-center space-x-3">
        <span class="text-sm text-gray-600 dark:text-gray-300 font-medium">
          {{ t('home.simpleMode') }}
        </span>
        
        <ElSwitch 
          v-model="isChecked"
          size="large"
          :active-text="t('home.professionalMode')"
          :inactive-text="t('home.simpleMode')"
          active-color="#3b82f6"
          inactive-color="#d1d5db"
          class="mode-switch"
        />
        
        <span class="text-sm text-gray-600 dark:text-gray-300 font-medium">
          {{ t('home.professionalMode') }}
        </span>
      </div>
    </ElTooltip>
    
    <!-- 模式说明 -->
    <div class="mt-2 text-xs text-gray-500 dark:text-gray-400 text-center max-w-xs">
      <span v-if="appStore.isProfessionalMode">
        {{ t('mode.professional.description') }}
      </span>
      <span v-else>
        {{ t('mode.simple.description') }}
      </span>
    </div>
  </div>
</template>

<style scoped>
.mode-switcher {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.mode-switch {
  --el-switch-on-color: #3b82f6;
  --el-switch-off-color: #d1d5db;
}

.dark .mode-switch {
  --el-switch-off-color: #4b5563;
}

/* 动画效果 */
.mode-switcher {
  transition: all 0.3s ease;
}

.mode-switcher:hover {
  transform: translateY(-1px);
}
</style>
